package com.xinya.taobaosale.ui.adapter;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;

import com.xinya.taobaosale.model.domain.CategoryBean;
import com.xinya.taobaosale.ui.fragment.DemoFragment;
import com.xinya.taobaosale.ui.fragment.HomePagerFragment;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName: HomeLayoutAdapter$
 * @Description: pagerAdapter
 * @Author: xinya
 * @CreateDate: 2021/2/2$ 10:44$
 * @UpdateRemark: 更新内容
 * @Version: 1.0
 */
public class HomeLayoutAdapter extends FragmentPagerAdapter {

    private List<CategoryBean> dataList = new ArrayList<>();

    public HomeLayoutAdapter(@NonNull FragmentManager fm) {
        super(fm);
    }

    public HomeLayoutAdapter(@NonNull FragmentManager fm, int behavior) {
        super(fm, behavior);
    }

    @Nullable
    @Override
    public CharSequence getPageTitle(int position) {
        return dataList.get(position).getTitle();
    }

    @NonNull
    @Override
    public Fragment getItem(int position) {
        return HomePagerFragment.newInstance(dataList.get(position));
    }

    @Override
    public int getCount() {
        return dataList.size();
    }

    public void setDataList(@NonNull List<CategoryBean> dataList) {
        this.dataList.clear();
        this.dataList.addAll(dataList);
        notifyDataSetChanged();
    }
}
